var beiMiCommon = require("BeiMiCommon");
cc.Class({
    extends: beiMiCommon,
    properties: {
        username: {
            default: null,
            type: cc.Node
        },
        zhadanNode: {
            default: null,
            type: cc.Node
        },
        id:{
            default: null,
            type: cc.Label
        },
        logo: {
            default: null,
            type: cc.Sprite
        }
    },
    onLoad() {
        //双扣
        //node.setPosition(-557,-309);//自己的位置
        //node.setPosition(590,100);//右边的位置
        //node.setPosition(-590,100);//左边的位置
        //麻将
        //node.setPosition(-570,-150);//自己的位置
        //node.setPosition(570,50);//右边的位置
        //node.setPosition(400,300);//上边的位置
        //node.setPosition(-570,50); //左边的位置

    },
    start() {
        //console.log(cc.beimi.openuser.v2)
        let self = this;
        this.username.getComponent(cc.Label).string=cc.beimi.openuser.name;
        this.id.string = cc.beimi.user.id.slice(0,6) || cc.beimi.openuser.id;
        var ip = cc.beimi.openuser.ip;
        var remoteUrl = cc.beimi.openuser.logo;
        if(remoteUrl){
            cc.loader.load({url: remoteUrl, type: 'png'}, function (err,tex) {
                var spriteFrame = new cc.SpriteFrame(tex, cc.Rect(0, 0, 132, 132));
                self.logo.spriteFrame = spriteFrame;
            });
        }
    },
    diuzhadan: function () {
        this.closeOpenWin();

        if (cc.beimi.openflag) {
            cc.beimi.openflag = false;
            setTimeout(function () {
                cc.beimi.openflag = true;
            }, 10000)

            console.log('animation start!')
            var newZhadan = cc.instantiate(this.zhadanNode);
            newZhadan.width = 120;
            newZhadan.height = 120;
            if (cc.beimi.openuser.type == 'shuangkou') {
                newZhadan.setPosition(-557, -309);
            } else {
                newZhadan.setPosition(-570, -150);
            }
            var parent = cc.find('Canvas');
            parent.addChild(newZhadan, 10, 'node');
            var pos = cc.find('Canvas/node');
            var destroyPos = cc.callFunc(function () { setTimeout(function () { newZhadan.destroy(); }, 1000) });
            if (cc.beimi.openuser.type == 'shuangkou') {
                if (cc.beimi.openuser.v2.x > 0) {
                    pos.runAction(cc.sequence(cc.moveTo(1.4, cc.v2(590, 100)), destroyPos));
                } else {
                    pos.runAction(cc.sequence(cc.moveTo(1.4, cc.v2(-590, 100)), destroyPos));
                }
            } else {
                if (cc.beimi.openuser.v2.y < 100) {
                    if (cc.beimi.openuser.v2.x > 0) {
                        pos.runAction(cc.sequence(cc.moveTo(1.4, cc.v2(570, 50)), destroyPos));
                    } else {
                        pos.runAction(cc.sequence(cc.moveTo(1.4, cc.v2(-570, 50)), destroyPos));
                    }
                } else {
                    pos.runAction(cc.sequence(cc.moveTo(1.4, cc.v2(400, 300)), destroyPos));
                }
            }

            var anim = newZhadan.getComponent(cc.Animation);
            anim.play('bomb');
        }
    }
});
